package initialize

import (
	"gitee.com/youbeiwuhuan/gin-practice/fizz-gorm2/global"
	"gitee.com/youbeiwuhuan/gin-practice/fizz-gorm2/global/config"
	"gitee.com/youbeiwuhuan/gin-practice/fizz-gorm2/tools/configs"
	"github.com/spf13/viper"
	"go.uber.org/zap"
	"gorm.io/gorm"
	"sync"
)

var (
	initOnce sync.Once
)

func GetGorm2() *gorm.DB {
	InitGorm2()
	return global.GormDb
}
func GetTotalConfig() configs.Configuration {
	InitAll()
	return config.TotalConfig
}

func GetViper() *viper.Viper {
	InitAll()
	return global.ViperCfg
}

func GetZap() *zap.Logger {
	if global.ZapLog == nil {
		InitZap()
	}

	return global.ZapLog
}

func InitAll() {
	initOnce.Do(func() {
		InitZap()
		loandConfig()
		InitGorm2()
	})
}
